package com.tuhao.www.util;

import java.beans.PropertyEditorSupport;
import java.io.UnsupportedEncodingException;

import org.springframework.util.StringUtils;

/**
 * 
 *
 */
public class StringConvertEditor extends PropertyEditorSupport {

	public void setAsText(String text) throws IllegalArgumentException {
		if (StringUtils.hasText(text)) {
			try {

				if (text.equals(new String(text.getBytes("iso-8859-1"),
						"iso-8859-1"))) {
					setValue(new String(text.getBytes("iso-8859-1"), "utf-8"));

				} else {
					setValue(text);
				}

			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		} else {
			setValue(null);
		}
	}
}
